<?php
/**
 * Copyright (c) 2006, PORTALIER Julien
 * 
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 * 
 * @package    FeatherPHP
 * @subpackage Librairies
 * @copyright  Copyright (c) 2006, Julien PORTALIER
 * @link       http://feather.portalier.com
 * @license    http://www.opensource.org/licenses/mit-license.php The MIT License
 */

class Cookies
{
	function check($key)
	{
		return isset($_COOKIE[$key]);
	}
	
	function read($key)
	{
		return Cookies::check($key) ? unserialize(base64_decode($_COOKIE[$key])) : null;
	}
	
	function write($key, $value, $expire='+1 month', $path='/', $domain=null, $secure=false)
	{
		if (is_string($expire))
			$expire = strtotime($expire);
		
		if (is_null($domain))
			$domain = Config::session_domain;
		
		$value = base64_encode(serialize($value));
		
		return setcookie($key, $value, $expire, $path, $domain, $secure);
	}
	
	function delete($key)
	{
		Cookies::write($key, '', '-1 month');
	}
}
?>